package com.coder520.mamabike.jms;

import com.alibaba.fastjson.JSONObject;
import com.coder520.mamabike.SendSMS.SendMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Component;

import javax.jms.Destination;

/**
 * Created by ASUS on 2017/8/15.
 */
@Component("sMSProcessor")
public class SMSProcessor {

    @Autowired
    private JmsMessagingTemplate jmsTemplate;

    @Autowired
    private SendMessage sendMessage;

    public void sendSmsToQueue(Destination destination,String message){
        jmsTemplate.convertAndSend(destination,message);

    }

    @JmsListener(destination = "sms.queue")
    public void doSendSmsMessage(String msg){
        JSONObject jsonObject = JSONObject.parseObject(msg);
        sendMessage.send(jsonObject.getString("phone"),jsonObject.getString("tepId"),jsonObject.getString("code"));

    }

}
